package com.chenglu.android.index.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenglu.android.R;
import com.chenglu.android.common.utils.GlideUtils;
import com.chenglu.android.common.utils.PxUtils;
import com.chenglu.android.index.bean.IndexRecomBean;
import com.chenglu.android.index.bean.PageListBean;

import java.util.List;

public class HomeSellAdapter extends BaseQuickAdapter<IndexRecomBean.Data.Records,BaseViewHolder> {

    private Context mContext ;

    private int columnCount = 4;

    public HomeSellAdapter(@Nullable Context context, List<IndexRecomBean.Data.Records> data) {
        super(R.layout.item_index_recom, data);
        this.mContext = context;

    }



    @Override
    protected void convert(@NonNull BaseViewHolder helper, IndexRecomBean.Data.Records item) {


        if(item!=null){

            TextView textView = helper.getView(R.id.title);
            ImageView imageView = helper.getView(R.id.iv_icon_center);
            textView.setText(item.getGoodsName());
            RequestOptions options = new RequestOptions()
                    .placeholder(R.color.white)
                    .error(R.color.white)
                    .transform(new RoundedCorners(PxUtils.dp2px(8)));
            Glide.with(mContext).load(item.getGoodsImg()).apply(options).into(imageView);

            GridLayoutManager.LayoutParams params = (GridLayoutManager.LayoutParams) helper.itemView.getLayoutParams();
            int screenWidth = mContext.getResources().getDisplayMetrics().widthPixels; //屏幕宽度
            params.width = screenWidth / columnCount;
            helper.itemView.setLayoutParams(params);

        }
    }

}